-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Inconsistent conversion of missing column names #44878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small comments, otherwise lgtm
@@ -91,7 +91,7 @@ def test_to_records_index_name(self): | |||
df.index = MultiIndex.from_tuples([("a", "x"), ("a", "y"), ("b", "z")]) | |||
df.index.names = ["A", None] | |||
rs = df.to_records() | |||
assert "level_0" in rs.dtype.fields | |||
assert "level_1" in rs.dtype.fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you maybe add a test checking the whole result?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cruel! But done.
doc/source/whatsnew/v1.4.0.rst
Outdated
@@ -854,6 +854,7 @@ Other | |||
- Bug in :meth:`DataFrame.shift` with ``axis=1`` and ``ExtensionDtype`` columns incorrectly raising when an incompatible ``fill_value`` is passed (:issue:`44564`) | |||
- Bug in :meth:`DataFrame.diff` when passing a NumPy integer object instead of an ``int`` object (:issue:`44572`) | |||
- Bug in :meth:`Series.replace` raising ``ValueError`` when using ``regex=True`` with a :class:`Series` containing ``np.nan`` values (:issue:`43344`) | |||
- Bug in :meth:`DataFrame.to_records` missing names filled incorrectly (:issue:`44818`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you specify a bit more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small comments, not 100% sold on the location (maybe @jbrockmendel can think of a better one), but ok. ping on green.
doc/source/whatsnew/v1.4.0.rst
Outdated
@@ -856,6 +856,7 @@ Other | |||
- Bug in :meth:`DataFrame.shift` with ``axis=1`` and ``ExtensionDtype`` columns incorrectly raising when an incompatible ``fill_value`` is passed (:issue:`44564`) | |||
- Bug in :meth:`DataFrame.diff` when passing a NumPy integer object instead of an ``int`` object (:issue:`44572`) | |||
- Bug in :meth:`Series.replace` raising ``ValueError`` when using ``regex=True`` with a :class:`Series` containing ``np.nan`` values (:issue:`43344`) | |||
- Bug in :meth:`DataFrame.to_records` where an incorrect n was used when missing names were replaced by level_n (:issue:`44818`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add backticks around the n
and level_n
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add backticks around the
n
andlevel_n
Done
pandas/core/common.py
Outdated
@@ -604,3 +604,10 @@ def is_builtin_func(arg): | |||
otherwise return the arg | |||
""" | |||
return _builtin_table.get(arg, arg) | |||
|
|||
|
|||
def fill_missing_names(names): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you type in and out here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, and added version and more docstring.
test location makes sense to me |
Hello @johnzangwill! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2021-12-16 13:28:03 UTC |
I suspect that @jreback was referring to the fact that I factored the logic into core/common.py.
and core/common is already imported as |
thanks @johnzangwill very nice! |
Factored out multiple occurances of missing name logic into common method.
DataFrame.to_records() changed to use common method rather than missing value count when filling missing names.
Index.to_frame() left alone for the time being.
Old behavior:
New behavior: